package com.ydw.java_default;

import com.ydw.model.Person;

import java.io.*;

/**
 * Created by ydw on 2017/7/5.
 */
public class Default {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Person person = new Person();
        person.setAge(18);
        person.setName("ydw");
        person.setId(1L);
        //自定义字节输出流
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        //自定义一个对象输出流
        ObjectOutputStream out = new ObjectOutputStream(os);
        //把对象写入输出流,进行序列化
        out.writeObject(person);
        byte[] bytes = os.toByteArray();

        //自己数组输入流
        ByteArrayInputStream is = new ByteArrayInputStream(bytes);
        //执行反序列化,从字节流中获取对象
        ObjectInputStream inputStream = new ObjectInputStream(is);
        Person ydw = (Person) inputStream.readObject();
        System.out.println(ydw);
    }
}
